package br.com.dev.tcc.view.apolice;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import br.com.dev.tcc.R;
import br.com.dev.tcc.adapter.ListaApolicesAdapter;
import br.com.dev.tcc.bean.Apolice;
import br.com.dev.tcc.view.apolice.ApolicesActivity.SearchClickListener;

public class ApolicesView {

	private Context ctx;
	private TextView tvSemItens;
	private ListView lista;
	private OnItemClickListener itemClickListener;
	private View btnBuscar;

	public ApolicesView(Activity controller, SearchClickListener listener,
			OnItemClickListener itemClickListener) {

		ctx = controller;
		this.itemClickListener = itemClickListener;
		lista = (ListView) controller.findViewById(R.id.list);
		tvSemItens = (TextView) controller.findViewById(R.id.tvNoItens);

		btnBuscar = controller.findViewById(R.id.btnSearch);
		btnBuscar.setOnClickListener(listener);
	}

	public void setLista(List<Apolice> apolices) {

		if (apolices.size() > 0) {

			ListaApolicesAdapter adapter = new ListaApolicesAdapter(ctx,
					apolices);
			lista.setVisibility(View.VISIBLE);
			lista.setAdapter(adapter);

			tvSemItens.setVisibility(View.GONE);

			setListClickListener();
		} else {

			tvSemItens.setVisibility(View.VISIBLE);
			lista.setVisibility(View.GONE);
		}
	}

	private void setListClickListener() {
		lista.setOnItemClickListener(itemClickListener);
	}

	public ListView getList() {
		return lista;
	}

	public TextView getTvSemItens() {
		return tvSemItens;
	}
}
